home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgLangD.iso / BORLAND TURBO / OWLSRC.PAK / CHECKBOX.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-06  |  4.9 KB  |  202 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows
  3. // Copyright (c) 1991, 1997 by Borland International, All Rights Reserved
  4. //
  5. //$Revision:   10.11  $
  6. //
  7. // Implemenation of class TCheckBox.  This defines the basic behavior for all
  8. // check boxes.
  9. //----------------------------------------------------------------------------
  10. #pragma hdrignore SECTION
  11. #include <owl/pch.h>
  12. #if !defined(OWL_CHECKBOX_H)
  13. # include <owl/checkbox.h>
  14. #endif
  15. #if !defined(OWL_GROUPBOX_H)
  16. # include <owl/groupbox.h>
  17. #endif
  18. #if !defined(OWL_APPLICAT_H)
  19. # include <owl/applicat.h>
  20. #endif
  21.  
  22. #if defined(BI_COMP_BORLANDC)
  23. # include <bwcc.h>
  24. #endif
  25.  
  26. OWL_DIAGINFO;
  27. DIAG_DECLARE_GROUP(OwlControl);
  28.  
  29. #if !defined(SECTION) || SECTION == 1
  30.  
  31. DEFINE_RESPONSE_TABLE1(TCheckBox, TButton)
  32.   EV_WM_GETDLGCODE,
  33.   EV_NOTIFY_AT_CHILD(BN_CLICKED, BNClicked),
  34. END_RESPONSE_TABLE;
  35.  
  36. //
  37. // constructor for a TCheckBox object
  38. //
  39. TCheckBox::TCheckBox(TWindow*        parent,
  40.                      int             id,
  41.                      const char far* title,
  42.                      int x, int y, int w, int h,
  43.                      TGroupBox*      group,
  44.                      TModule*        module)
  45. :
  46.   TButton(parent, id, title, x, y, w, h, false, module)
  47. {
  48.   Group = group;
  49.   //
  50.   // Don't use TButton's inherited style - it conflicts with BS_AUTOCHECKBOX
  51.   //
  52.   Attr.Style = WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_AUTOCHECKBOX;
  53.  
  54.   TRACEX(OwlControl, OWL_CDLEVEL, "TCheckBox constructed @" << (void*)this);
  55. }
  56.  
  57. //
  58. // constructor for a TCheckBox to be associated with a MS-Windows interface
  59. // element created by MS-Windows from a resource definition
  60. //
  61. // data transfer is enabled for the TCheckBox
  62. //
  63. TCheckBox::TCheckBox(TWindow*   parent,
  64.                      int        resourceId,
  65.                      TGroupBox* group,
  66.                      TModule*   module)
  67. :
  68.   TButton(parent, resourceId, module)
  69. {
  70.   Group = group;
  71.   EnableTransfer();
  72.  
  73.   TRACEX(OwlControl, OWL_CDLEVEL, "TCheckBox constructed from resource @" << (void*)this);
  74. }
  75.  
  76. //
  77. // Output a trace message if using the diagnostic libraries.
  78. //
  79. TCheckBox::~TCheckBox()
  80. {
  81.   TRACEX(OwlControl, OWL_CDLEVEL, "TCheckBox destructed @" << (void*)this);
  82. }
  83.  
  84. //
  85. // Return name of predefined BWCC or Windows check box class
  86. //
  87. char far*
  88. TCheckBox::GetClassName()
  89. {
  90. #if defined(BI_COMP_BORLANDC)
  91.   if (GetApplication()->BWCCEnabled()) {
  92.     TRACEX(OwlControl, 1, "BWCC checkbox used for classname @" << (void*)this);
  93.     return CHECK_CLASS;
  94.   }
  95. #endif
  96.   TRACEX(OwlControl, 1, "Regular checkbox used for classname @" << (void*)this);
  97.   return "BUTTON";
  98. }
  99.  
  100. //
  101. // transfers state information for the TCheckBox
  102. //
  103. // the direction passed specifies whether data is to be read from or
  104. // written to the passed buffer, or whether the data element size is simply
  105. // to be returned
  106. //
  107. // the return value is the size (in bytes) of the transfer data
  108. //
  109. uint
  110. TCheckBox::Transfer(void* buffer, TTransferDirection direction)
  111. {
  112.   if (direction == tdGetData)
  113.     *(uint16*)buffer = (uint16)GetCheck();
  114.  
  115.   else if (direction == tdSetData)
  116.     SetCheck(*(uint16*)buffer);
  117.  
  118.   return sizeof(uint16);
  119. }
  120.  
  121. //
  122. // sets the check state
  123. //
  124. // unchecks, checks, or grays the checkbox (if 3-state) according to the
  125. // CheckFlag passed (pass BF_UNCHECKED(0), BF_CHECKED(1), or BF_GRAYED(2))
  126. //
  127. // if a Group has been specified for the TCheckBox, notifies the Group that
  128. // the state of the check box has changed
  129. //
  130. void
  131. TCheckBox::SetCheck(uint check)
  132. {
  133.   PRECONDITION(GetHandle());
  134.   SendMessage(BM_SETCHECK, check);
  135.  
  136.   if (Group)
  137.     Group->SelectionChanged(Attr.Id);
  138. }
  139.  
  140. //
  141. // toggles the check state of the check box
  142. //
  143. void
  144. TCheckBox::Toggle()
  145. {
  146.   if ((GetWindowLong(GWL_STYLE) & BS_AUTO3STATE) == BS_AUTO3STATE)
  147.     SetCheck((GetCheck() + 1) % 3);
  148.  
  149.   else
  150.     SetCheck((GetCheck() + 1) % 2);
  151. }
  152.  
  153. //
  154. // responds to an incoming BN_CLICKED message
  155. //
  156. // if a Group has been specified for the TCheckBox, notifies the Group that
  157. // the state of this TCheckBox has changed
  158. //
  159. void
  160. TCheckBox::BNClicked()
  161. {
  162.   if (Group)
  163.     Group->SelectionChanged(Attr.Id);
  164.  
  165.   DefaultProcessing();  // give parent an opportunity to handle...
  166. }
  167.  
  168. #endif
  169. #if !defined(SECTION) || SECTION == 2
  170.  
  171. IMPLEMENT_STREAMABLE1(TCheckBox, TButton);
  172.  
  173. #if !defined(BI_NO_OBJ_STREAMING)
  174.  
  175. //
  176. // reads an instance of TCheckBox from the passed ipstream
  177. //
  178. void*
  179. TCheckBox::Streamer::Read(ipstream& is, uint32 /*version*/) const
  180. {
  181.   ReadBaseObject((TButton*)GetObject(), is);
  182.   is >> GetObject()->Group;
  183.   return GetObject();
  184. }
  185.  
  186. #if !defined(BI_NO_OBJ_STREAMING)
  187.  
  188. //
  189. // writes the TCheckBox to the passed opstream
  190. //
  191. void
  192. TCheckBox::Streamer::Write(opstream& os) const
  193. {
  194.   WriteBaseObject((TButton*)GetObject(), os);
  195.   os << GetObject()->Group;
  196. }
  197. #endif  // if !defined(BI_NO_OBJ_STREAMING)
  198.  
  199. #endif  // if !defined(BI_NO_OBJ_STREAMING)
  200.  
  201. #endif
  202.